﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Resources;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Converter;
using csla4Skeleton.UI.SL.Resources.Utility;
using csla4Skeleton.UI.SL.DanhMuc.DM_HangHoa;
using csla4Skeleton.UI.SL.DanhMuc.DM_TinhChatHangHoa;
using csla4Skeleton.UI.SL.NghiepVu.TinhGiaThanh.GT_CPTrucTiep;
using csla4Skeleton.UI.SL.NghiepVu.TaiSanCoDinh.DM_LoaiDoiTuongTHCP;
using Accounting.Library;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using System.ComponentModel;
using Utility;
using Accounting.Library.Utility;

namespace csla4Skeleton.UI.SL.TongHop.TH_SoChiTiet
{
    public partial class TH_SoChiTiet_ChildWindow: ChildWindow
    {

        #region ISupportNavigation Members
        List<Control> controls = new List<Control>();
        public bool CreateBookmarkAfterLoadCompleted
        {
            get { return true; }
        }

        public event EventHandler LoadCompleted;

        protected virtual void OnLoadCompleted()
        {
            if (LoadCompleted != null)
                LoadCompleted(this, EventArgs.Empty);
        }

        public void SetParameters(string parameters)
        {
            try
            {
                if (parameters == "")
                    Khoa = null;
                else
                    Khoa = Int32.Parse(parameters);
            }
            catch
            {
                Khoa = null;
            }
        }

        public string Title
        {
            get { return "SoChiTiet"; }
        }

       
        #endregion

        #region Load Methods
        private System.Nullable<int> Khoa = null;
        private object  chiTietChildObject;
        private string Mode;
        public TH_SoChiTiet_ChildWindow(object chiTietChild, string Mode)
        {
            LocalizationConverter converter = new LocalizationConverter();
            converter.LocalResourceManager = new ResourceManager("csla4Skeleton.UI.SL.TongHop.TH_SoChiTiet.Resources", Assembly.GetExecutingAssembly());
            this.Resources.Add("Localization", converter);
            
            InitializeComponent();

            this.chiTietChildObject = chiTietChild;
            this.Mode = Mode;
      
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                System.Windows.Data.CollectionViewSource th_SoChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["TH_SoChiTiet_ListViewModelSource"];

                if (this.Mode.Equals(BusinessConfiguration.Configuration.CPTrucTiepFilterMode))
                {
                    GT_CPTrucTiep_ChiTietChild chiTietChild = this.chiTietChildObject as GT_CPTrucTiep_ChiTietChild;
                    string listTaiKhoan = "";
                    if (chiTietChild.Tk_621 != 0 && chiTietChild.Tk_621 != null)
                        listTaiKhoan = listTaiKhoan + "621;";
                    if (chiTietChild.Tk_622 != 0 && chiTietChild.Tk_622 != null)
                        listTaiKhoan = listTaiKhoan + "622;";
                    if (chiTietChild.Tk_6231 != 0 && chiTietChild.Tk_6231 != null)
                        listTaiKhoan = listTaiKhoan + "6231;";
                    if (chiTietChild.Tk_6232 != 0 && chiTietChild.Tk_6232 != null)
                        listTaiKhoan = listTaiKhoan + "6232;";
                    if (chiTietChild.Tk_6233 != 0 && chiTietChild.Tk_6233 != null)
                        listTaiKhoan = listTaiKhoan + "6233;";
                    if (chiTietChild.Tk_6234 != 0 && chiTietChild.Tk_6234 != null)
                        listTaiKhoan = listTaiKhoan + "6234;";
                    if (chiTietChild.Tk_6237 != 0 && chiTietChild.Tk_6237 != null)
                        listTaiKhoan = listTaiKhoan + "6237;";
                    if (chiTietChild.Tk_6238 != 0 && chiTietChild.Tk_6238 != null)
                        listTaiKhoan = listTaiKhoan + "6238;";
                    if (chiTietChild.Tk_6271 != 0 && chiTietChild.Tk_6271 != null)
                        listTaiKhoan = listTaiKhoan + "6271;";
                    if (chiTietChild.Tk_6272 != 0 && chiTietChild.Tk_6272 != null)
                        listTaiKhoan = listTaiKhoan + "6272;";
                    if (chiTietChild.Tk_6273 != 0 && chiTietChild.Tk_6273 != null)
                        listTaiKhoan = listTaiKhoan + "6273;";
                    if (chiTietChild.Tk_6274 != 0 && chiTietChild.Tk_6274 != null)
                        listTaiKhoan = listTaiKhoan + "6274;";
                    if (chiTietChild.Tk_6277 != 0 && chiTietChild.Tk_6277 != null)
                        listTaiKhoan = listTaiKhoan + "6277;";
                    if (chiTietChild.Tk_6278 != 0 && chiTietChild.Tk_6278 != null)
                        listTaiKhoan = listTaiKhoan + "6278;";

                    TH_SoChiTiet_ListViewModel th_SoChiTiet_ListViewModel = new TH_SoChiTiet_ListViewModel("FilterInChiPhiTrucTiep", chiTietChild.HangHoaId, chiTietChild.DoiTuongTHCPId, listTaiKhoan);
                    th_SoChiTiet_CollectionViewSource.Source = new List<object> { th_SoChiTiet_ListViewModel };
                }
                else if (this.Mode.Equals(BusinessConfiguration.Configuration.CPPhanBoFilterMode))
                {
                    GT_CPPhanBo_ChiTietChild chiTietChild = this.chiTietChildObject as GT_CPPhanBo_ChiTietChild;
                    string listTaiKhoan = "";
                    if (chiTietChild.Tk_621 != 0 && chiTietChild.Tk_621 != null)
                        listTaiKhoan = listTaiKhoan + "621;";
                    if (chiTietChild.Tk_622 != 0 && chiTietChild.Tk_622 != null)
                        listTaiKhoan = listTaiKhoan + "622;";
                    if (chiTietChild.Tk_6231 != 0 && chiTietChild.Tk_6231 != null)
                        listTaiKhoan = listTaiKhoan + "6231;";
                    if (chiTietChild.Tk_6232 != 0 && chiTietChild.Tk_6232 != null)
                        listTaiKhoan = listTaiKhoan + "6232;";
                    if (chiTietChild.Tk_6233 != 0 && chiTietChild.Tk_6233 != null)
                        listTaiKhoan = listTaiKhoan + "6233;";
                    if (chiTietChild.Tk_6234 != 0 && chiTietChild.Tk_6234 != null)
                        listTaiKhoan = listTaiKhoan + "6234;";
                    if (chiTietChild.Tk_6237 != 0 && chiTietChild.Tk_6237 != null)
                        listTaiKhoan = listTaiKhoan + "6237;";
                    if (chiTietChild.Tk_6238 != 0 && chiTietChild.Tk_6238 != null)
                        listTaiKhoan = listTaiKhoan + "6238;";
                    if (chiTietChild.Tk_6271 != 0 && chiTietChild.Tk_6271 != null)
                        listTaiKhoan = listTaiKhoan + "6271;";
                    if (chiTietChild.Tk_6272 != 0 && chiTietChild.Tk_6272 != null)
                        listTaiKhoan = listTaiKhoan + "6272;";
                    if (chiTietChild.Tk_6273 != 0 && chiTietChild.Tk_6273 != null)
                        listTaiKhoan = listTaiKhoan + "6273;";
                    if (chiTietChild.Tk_6274 != 0 && chiTietChild.Tk_6274 != null)
                        listTaiKhoan = listTaiKhoan + "6274;";
                    if (chiTietChild.Tk_6277 != 0 && chiTietChild.Tk_6277 != null)
                        listTaiKhoan = listTaiKhoan + "6277;";
                    if (chiTietChild.Tk_6278 != 0 && chiTietChild.Tk_6278 != null)
                        listTaiKhoan = listTaiKhoan + "6278;";

                    TH_SoChiTiet_ListViewModel th_SoChiTiet_ListViewModel = new TH_SoChiTiet_ListViewModel("FilterInChiPhiPhanBo", chiTietChild.HangHoaId, (int)chiTietChild.DoiTuongTHCPId, listTaiKhoan);
                    th_SoChiTiet_CollectionViewSource.Source = new List<object> { th_SoChiTiet_ListViewModel };
                }
            }
        }

       
        #endregion

        #region Event Handle
      
      
        private RadGridView GetActiveGridView()
        {
            return TH_SoChiTiet_GridView;
        }

        public TH_SoChiTiet_ListViewModel GetViewModel()
        {
            System.Windows.Data.CollectionViewSource GT_CPTrucTiep_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["TH_SoChiTiet_ListViewModelSource"];
            return ((List<object>)GT_CPTrucTiep_CollectionViewSource.Source)[0] as TH_SoChiTiet_ListViewModel;
        }
        #endregion
  
    }
}
